namespace CCStatistics.Domain.Api
{
    using System;
    using System.Collections.Generic;
    using System.Xml;

    using Interfaces;

    using ThoughtWorks.CruiseControl.Core;
    using ThoughtWorks.CruiseControl.Core.Publishers.Statistics;
    using ThoughtWorks.CruiseControl.Remote;

    /// <summary>
    /// This class provides a wrapper for the CruiseControl Project class
    /// </summary>
    public class CCStatsProject : ICCStatsProject
    {
        private readonly String _buildLogDirectory;

        private readonly ICCStatisticsPublisher _statisticsPublisher;

        private readonly IProject _wrappedProject;

        /// <summary>
        /// Initializes a new instance of the <see cref="CCStatsProject"/> class.
        /// </summary>
        /// <param name="projectToWrap">The project to wrap.</param>
        /// <param name="statisticsPublisher">The statistics publisher.</param>
        /// <param name="buildLogDirectory">The build log directory.</param>
        public CCStatsProject(IProject projectToWrap,
                              ICCStatisticsPublisher statisticsPublisher,
                              String buildLogDirectory)
        {
            if (projectToWrap == null)
                throw new ArgumentNullException("projectToWrap");
            if (statisticsPublisher == null)

                throw new ArgumentNullException("statisticsPublisher");

            if (String.IsNullOrEmpty(buildLogDirectory))
                throw new ArgumentNullException("buildLogDirectory");

            _wrappedProject = projectToWrap;
            _statisticsPublisher = statisticsPublisher;
            _buildLogDirectory = buildLogDirectory;
        }

        #region ICCStatsProject Members

        /// <summary>
        /// Gets the active statistics for a publisher.  This includes the default stats determined by <see cref="StatisticsBuilder"/>, and any additons or exclusions to these
        /// </summary>
        /// <returns></returns>
        public List<Statistic> StatisticsForPublisher
        {
            get
            {
                return _statisticsPublisher.ActiveStatistics;
            }
        }

        /// <summary>
        /// Gets the log directory.
        /// </summary>
        /// <returns></returns>
        public string BuildLogDirectory
        {
            get { return _buildLogDirectory; } 
        }

        /// <summary>
        /// Purges the specified purge working directory.
        /// </summary>
        /// <param name="purgeWorkingDirectory">if set to <c>true</c> [purge working directory].</param>
        /// <param name="purgeArtifactDirectory">if set to <c>true</c> [purge artifact directory].</param>
        /// <param name="purgeSourceControlEnvironment">if set to <c>true</c> [purge source control environment].</param>
        public void Purge(bool purgeWorkingDirectory, bool purgeArtifactDirectory, bool purgeSourceControlEnvironment)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Initializes this instance.
        /// </summary>
        public void Initialize()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Creates the project status.
        /// </summary>
        /// <param name="integrator">The integrator.</param>
        /// <returns></returns>
        public ProjectStatus CreateProjectStatus(IProjectIntegrator integrator)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Aborts the running build.
        /// </summary>
        /// <returns></returns>
        /// Documentation Created 6/19/2008
        public string AbortRunningBuild()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Adds the message.
        /// </summary>
        /// <param name="message">The message.</param>
        public void AddMessage(Message message)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Notifies the state of the pending.
        /// </summary>
        public void NotifyPendingState()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Notifies the state of the sleeping.
        /// </summary>
        public void NotifySleepingState()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets the name.
        /// </summary>
        /// <value>The name.</value>
        public string Name
        {
            get { return _wrappedProject.Name; }
        }

        /// <summary>
        /// Gets the category.
        /// </summary>
        /// <value>The category.</value>
        public string Category
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the triggers.
        /// </summary>
        /// <value>The triggers.</value>
        public ITrigger Triggers
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the web URL.
        /// </summary>
        /// <value>The web URL.</value>
        public string WebURL
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the working directory.
        /// </summary>
        /// <value>The working directory.</value>
        public string WorkingDirectory
        {
            get { return _wrappedProject.WorkingDirectory; }
        }

        /// <summary>
        /// Gets the artifact directory.
        /// </summary>
        /// <value>The artifact directory.</value>
        public string ArtifactDirectory
        {
            get { return _wrappedProject.ArtifactDirectory; }
        }

        /// <summary>
        /// Gets the external links.
        /// </summary>
        /// <value>The external links.</value>
        public ExternalLink[] ExternalLinks
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the statistics.
        /// </summary>
        /// <value>The statistics.</value>
        public XmlDocument Statistics
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the modification history.
        /// </summary>
        /// <value>The modification history.</value>
        /// Documentation Created 6/19/2008
        public string ModificationHistory
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the RSS feed.
        /// </summary>
        /// <value>The RSS feed.</value>
        /// Documentation Created 6/19/2008
        public string RSSFeed
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the get integration repository.
        /// </summary>
        /// <value>The get integration repository.</value>
        public IIntegrationRepository IntegrationRepository
        {
            get { return _wrappedProject.IntegrationRepository; }
        }

        /// <summary>
        /// Gets or sets the name of the queue.
        /// </summary>
        /// <value>The name of the queue.</value>
        public string QueueName
        {
            get { throw new NotImplementedException(); }
            set { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the queue priority.
        /// </summary>
        /// <value>The queue priority.</value>
        public int QueuePriority
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the current activity.
        /// </summary>
        /// <value>The current activity.</value>
        public ProjectActivity CurrentActivity
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Gets the wrapper class for the Statistics Publisher case as the interface.
        /// This is a key area where we had to add a new overload for the Run method
        /// in order for it to accept a forced XML file (from history).
        /// This is the key architectural extention which allows this application
        /// to work
        /// </summary>
        /// <returns></returns>
        public ICCStatisticsPublisher StatsPostPublisher
        {
            get { return _statisticsPublisher; }
        }

        /// <summary>
        /// Integrates the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public IIntegrationResult Integrate(IntegrationRequest request)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}